//
//  RFChoice1ViewController.m
//  demoapp
//
//  Created by MingmingSun on 15/8/27.
//  Copyright (c) 2015年 pingplusplus. All rights reserved.
//

#import "RFChoice1ViewController.h"
#import "RFChoice2ViewController.h"

@interface RFChoice1ViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong) NSArray *barberArray;
@property(nonatomic,weak) IBOutlet UITableView *listView;
@property(nonatomic,assign) int chooseRF;

@end

@implementation RFChoice1ViewController

@synthesize listView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        switch (APPALL.myType) {
            case hairTangFa:
                self.title = @"烫发";
                self.barberArray = @[@"热烫",@"冷烫"];
                break;
            case hairRanFa:
                self.title = @"染发";
                self.barberArray = @[@"染色",@"漂色",@"条染",@"片染",@"打蜡",@"综合"];
                break;
            case hairHuli:
                self.title = @"护理";
                self.barberArray = @[@"头发护理",@"头皮护理",@"水疗护理"];
                break;
            default:
                break;
        }
        self.chooseRF = 0;
        self.navigationItem.leftBarButtonItem =
        [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrow_white"]
                                         style:UIBarButtonItemStyleDone
                                        target:self
                                        action:@selector(backPressed:)];
    }
    return self;
}

-(void)backPressed:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case 0:
            return self.barberArray.count;
        default:
            return 1;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
            return 44.0f;
        default:
            return 60.0f;
    }
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = nil;
    static NSString *inde;
    switch (indexPath.section) {
        case 0:{
            inde = @"RF1ID";
            cell = [tableView dequeueReusableCellWithIdentifier:inde];
            if (cell == nil) {
                NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"RF1Cell" owner:self options:nil];
                cell = [nib objectAtIndex:0];
            }
            NSString *str = [self.barberArray objectAtIndex:indexPath.row];
            UILabel *lab1 = (UILabel*)[cell viewWithTag:1];
            UILabel *lab2 = (UILabel*)[cell viewWithTag:2];
            UIImageView *img99 = (UIImageView*)[cell viewWithTag:99];
            lab1.text = [NSString stringWithFormat:@"我要%@",str];
            lab2.text = [NSString stringWithFormat:@"什么是%@",str];
            img99.hidden = (self.chooseRF != indexPath.row);
        }
            break;
        case 1:{
            inde = @"DDButtonID";
            cell = [tableView dequeueReusableCellWithIdentifier:inde];
            if (cell == nil) {
                NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DDButton" owner:self options:nil];
                cell = [nib objectAtIndex:0];
            }
            UIButton *but = (UIButton*)[cell viewWithTag:1];
            [but setTitle:@"下一步" forState:UIControlStateNormal];
            [but addTarget:self action:@selector(ddPressed:) forControlEvents:UIControlEventTouchUpInside];
        }
            break;
        default:
            break;
    }
    return cell;
}

-(void)ddPressed:(id)sender{
    APPALL.rfType = [self.barberArray objectAtIndex:self.chooseRF];
    RFChoice2ViewController *vc = [RFChoice2ViewController new];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0){
        self.chooseRF = indexPath.row;
        [self.listView reloadData];
    }
}

@end